Zum Hauptinhalt springen

Einheit 14 — Vom CURL-Befehl zum Post Agent

Was du nach dieser Einheit weißt: Du kannst jeden CURL-Befehl systematisch in eine vollständige Post-Agent-Konfiguration übersetzen.


Die Übersetzungstabelle

CURLPost Agent
-X GET/POST/PUT/PATCH/DELETEmethod
https://...post_url
-H "Authorization: ..."headersAuthorization
-H "Content-Type: ..."content_type
-d '...' / --data-raw '...'payload
--insecure(SSL Verify deaktivieren in Einstellungen)
-u user:passcontent_type: form + Basic Auth im Header

Schritt-für-Schritt-Beispiel

Gegeben: CURL-Befehl vom API-Anbieter

curl -X POST https://api.example.com/v1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer abc123secret" \
-H "X-Tenant-ID: firma42" \
-d '{
"customer_id": 42,
"product_id": 789,
"quantity": 3,
"note": "Eilbestellung"
}' \
--insecure

Übersetzung in Post-Agent-Konfiguration:

{
"post_url": "https://api.example.com/v1/orders",
"method": "post",
"content_type": "json",
"headers": {
"Authorization": "Bearer {% credential api_token %}",
"X-Tenant-ID": "firma42"
},
"payload": {
"customer_id": "{{ customer_id }}",
"product_id": "{{ product_id }}",
"quantity": "{{ quantity }}",
"note": "{{ note }}"
},
"emit_messages": true,
"output_mode": "merge"
}

Was sich geändert hat:

  1. Content-Type: application/jsoncontent_type: json (Post Agent setzt den Header automatisch)

  2. Authorization: Bearer abc123secret → Token in Credential-Store ausgelagert, referenziert mit {% credential api_token %}

  3. Feste Werte im Body → Liquid-Templates für dynamische Werte aus der eingehenden Nachricht

  4. --insecure → in der 42°OS Instanzkonfiguration oder Agent-Einstellungen deaktivieren


Dynamische URLs mit Liquid

CURL mit fester Ressourcen-ID:

curl https://api.example.com/v1/customers/42

Post-Agent-URL mit Liquid:

post_url: https://api.example.com/v1/customers/{{ customer_id }}

GET-Anfragen mit Query-Parametern

CURL:

curl "https://api.example.com/v1/orders?status=pending&limit=50&from=2026-01-01"

Post Agent:

{
"post_url": "https://api.example.com/v1/orders",
"method": "get",
"payload": {
"status": "pending",
"limit": "50",
"from": "{{ from_date }}"
}
}

Bei GET werden die payload-Werte automatisch als Query-Parameter an die URL angehängt.


Basic Auth übersetzen

CURL:

curl https://api.example.com/v1/data \
-u "mein_user:mein_passwort"

Post Agent:

{
"post_url": "https://api.example.com/v1/data",
"method": "get",
"headers": {
"Authorization": "Basic {% credential basic_auth_encoded %}"
}
}

Im Credential-Store: basic_auth_encoded enthält benutzername:passwort in Base64-Kodierung.

Alternativ unterstützt der Post Agent Basic Auth direkt — prüfe die aktuelle Agenten-Dokumentation.


Die Response verarbeiten

Nach dem Post Agent steht die Antwort in der Nachricht:

{
"status": 201,
"headers": { "Content-Type": "application/json" },
"body": "{\"id\": 1042, \"status\": \"pending\"}"
}

Wichtig: body ist ein String, kein JSON-Objekt. Um ihn weiterzuverarbeiten, muss er per JSON Parse Agent umgewandelt werden:

Post Agent → JSON Parse Agent → Switch Agent (auf status-Code prüfen) → ...

Nach dem JSON Parse Agent:

{
"status": 201,
"body": {
"id": 1042,
"status": "pending"
}
}

Jetzt kann mit {{ body.id }} auf die neue Bestellungs-ID zugegriffen werden.


Weiter: Übung — API-Endpunkte erkunden und testen